package com.palrevo.utils;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.palrevo.common.Constants;

/**
 * Contains all configuration loaded from Configs.properties File.
 *
 * @author AAsha
 */
public abstract class Configs {

    private static Properties configProperties;

    /**
     *
     */
    public static void loadConfigs() {

        InputStream propertiesFileIS = Configs.class.getClassLoader().getResourceAsStream(Constants.CONFIGS_PROPERTIES_FILE);

        try {
            configProperties = new Properties();
            configProperties.load(propertiesFileIS);

        } catch (FileNotFoundException e) {
            Log.error(Configs.class, e.getMessage(), e);
        } catch (IOException e) {
            Log.error(Configs.class, e.getMessage(), e);
        } finally {
            try {
                propertiesFileIS.close();
            } catch (IOException e) {
                Log.error(Configs.class, e.getMessage(), e);
            }
        }

    }

    /**
     *
     * @param configName
     * @return String - config property value.
     */
    public static String getConfigValue(String configName) {
    	
    	if(configProperties == null || configProperties.get(configName) == null){
    		loadConfigs();
    	}
    	
        return configProperties.getProperty(configName);
    }
}
